<?php
/**
 * Description of ControllerBase
 * @author HAO SBaseController
 */
class ControllerBase extends CController {
    const FLASH_ERROR 	= 'error';
    const FLASH_NOTICE 	= 'notice';
    const FLASH_SUCCESS = 'success';
    public $layout 		= LAYOUT;
    public $menu 		= array();
    public $breadcrumbs = array();
    public $title 		= SITE_NAME;
    public $description = '';
    public $keyword 	= '';
    public $mainTitle 	= '';
    public function init() {
		self::setLoginUrl();
    	// Add jQuery library
        Yii::app()->language = LOCALE;	}

	private function setLoginUrl(){
		$url = array('/user/login');
		if (isset(Yii::app()->controller->module))
			$url = array('/user/login/admin');

		Yii::app()->getModule('user')->loginUrl = $url;
		Yii::app()->getModule('user')->returnLogoutUrl = $url;
		Yii::app()->user->loginUrl = $url;
	}
    public function setFlash($message, $category = self::FLASH_SUCCESS) {
        Yii::app()->user->setFlash($category, $message);
    }
    public function getFlash($category = self::FLASH_SUCCESS) {
        if (Yii::app()->user->hasFlash($category)) {
        	$classFlash = ($category !== self::FLASH_ERROR && $category !== self::FLASH_NOTICE && $category !== self::FLASH_SUCCESS) ? self::FLASH_NOTICE : $category;
        	return "<div class='flash-{$classFlash}'>" . Yii::app()->user->getFlash($category) . "</div>";
        }
    }
	public function printFlash($category = self::FLASH_SUCCESS) {
	 	if (Yii::app()->user->hasFlash($category)) {
        	$classFlash = ($category !== self::FLASH_ERROR && $category !== self::FLASH_NOTICE && $category !== self::FLASH_SUCCESS) ? self::FLASH_NOTICE : $category;
        	echo "<div class='flash-{$classFlash}'>" . Yii::app()->user->getFlash($category) . "</div>";
        }
    }
}